package com.github.sbb.sherry.console.exception;


import org.springframework.http.HttpStatus;

/**
 * The type Base exception.
 */
public abstract class BaseException extends RuntimeException {

  /**
   * 异常打印日志级别.
   *
   * @return the log level
   * @see ErrorOutputLogLevelEnum
   */
  public abstract ErrorOutputLogLevelEnum getLogLevel();

  private final HttpStatus httpStatus;
  private final ErrorMessage errorMessage;

  /**
   * Constructs a new runtime exception with the specified detail message. The cause is not initialized, and may subsequently be initialized
   * by a call to {@link #initCause}.
   *
   * @param httpStatus         the http status
   * @param errorStatusMessage the error status message
   */
  public BaseException(HttpStatus httpStatus, ErrorMessage errorStatusMessage) {
    super(errorStatusMessage.getMessage());
    this.httpStatus = httpStatus;
    this.errorMessage = errorStatusMessage;
  }

  /**
   * Instantiates a new Base exception.
   *
   * @param httpStatus the http status
   * @param code       the code
   * @param message    the message
   */
  public BaseException(HttpStatus httpStatus, String code, String message) {
    super(message);
    this.httpStatus = httpStatus;
    this.errorMessage = new ErrorMessage();
    errorMessage.setCode(code);
    errorMessage.setMessage(message);
  }

  /**
   * Gets http status.
   *
   * @return the http status
   */
  public HttpStatus getHttpStatus() {
    return httpStatus;
  }

  /**
   * Gets error message.
   *
   * @return the error message
   */
  public ErrorMessage getErrorMessage() {
    return errorMessage;
  }
}
